package com.itao.bytebuddy;

import com.itao.util.ResourceUtil;
import net.bytebuddy.ByteBuddy;

import java.io.File;
import java.io.IOException;

/**
 * @Author sjt
 * @CreateTime 2023/10/16 9:56
 */
public class CreateClass {
    public static void main(String[] args) {
        // 命名策略
        // var strategy = new NamingStrategy.Suffixing("test");
        try (
                // Unloaded未加载到jvm的类
                var unloaded = new ByteBuddy()
                        // 指定命名策略
                        //.with(strategy)
                        .subclass(SupperClass.class)
                        // 指定生成类的全类名
                        .name("com.itao.bytebuddy.SubClass")
                        .make()
        ) {
            // 将生成的类保存到文件中
            unloaded.saveIn(new File(ResourceUtil.getClassPath(CreateClass.class)));
            // 将生成的类注入到jar中
            //unloaded.inject(new File("xx/xx.jar"));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
